package com.secondriver.url.match;

import static org.junit.Assert.*;

import java.util.Collection;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import com.secondriver.url.filter.match.URLPatternMatch;
import com.secondriver.url.filter.match.groovy.AntURLPatternMatch
import com.secondriver.url.filter.match.groovy.DefalutURLPatternMatch;
import com.secondriver.url.filter.match.groovy.SimpleURLPatternMatch

@RunWith(value=Parameterized.class)
class TestAntURLPatternMatch {

	def static URLPatternMatch match;

	def static urls =[
		'/abc/*',
		'/abc/**/xyz/index.jsp',
		'/abc/1?3/*.jsp',
		'/abc/123/*23?.jsp'
	] as HashSet;

	def request;

	def result;

	public TestAntURLPatternMatch(String request, boolean result ) {
		this.request=request;
		this.result=result;
	}

	@Parameters
	public static Collection data(){
		return		[
			['/abc/1%3/..jsp', true] as Object[],
			['/abc/xyz', true] as Object[],
			['/abc/123/xyz/index.jsp', true] as Object[],
			['/abc/143/hello.jsp', true] as Object[],
			['/abc/123/hello234.jsp', true] as Object[],
			['/abc/123/456/xyz/index.jsp', true] as Object[],
			['/abc/123/456/789/xyz/index', false] as Object[],
			['/abc/123/123/.jsp', false] as Object[]
		];
	}

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		match=new AntURLPatternMatch();
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Test
	public void testAnt(){
		assertEquals(result, match.isPass(request, urls));
	}
}
